/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * test_mapping.c
 */

#include <stdlib.h>
#include "runner_fa.h"

static void test_alloc_sys_block() {
	SysBlock *sys = alloc_sys_block();
	assert_non_null(sys);
}

static void test_alloc_mapping() {
	Mapping *mapping = alloc_mapping();
	assert_non_null(mapping);
}

static void test_get_sys_mapping() {
	Mapping *mapping = create_sys_mapping_1();
	Queue *queue = init_queue();
	enqueue(queue, mapping);
	assert_ptr_equal(mapping, get_sys_mapping(queue, SYS_TEMPLATE_NAME));
	assert_null(get_sys_mapping(queue, NULL));
	assert_null(get_sys_mapping(NULL, SYS_TEMPLATE_NAME));
	assert_null(get_sys_mapping(NULL, NULL));
}

static void test_calc_mapping_prefix() {
	Mapping *mapping = create_sys_mapping_1();
	assert_string_equal(calc_mapping_prefix(mapping), "def");
	assert_null(calc_mapping_prefix(NULL));
}

int main(int argc, char **argv) {
	const struct CMUnitTest tests[] = {
			cmocka_unit_test(test_alloc_sys_block),
			cmocka_unit_test(test_alloc_mapping),
			cmocka_unit_test(test_get_sys_mapping),
			cmocka_unit_test(test_calc_mapping_prefix),
	};
	return cmocka_run_group_tests(tests, NULL, NULL);
}
